package com.zg.shop.categorysecond;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.zg.shop.common.Constant;
import com.zg.shop.product.PageBean;

@Transactional
public class CategorySecondService {
	private CategorySecondDao categorySecondDao;
	
	public void setCategorySecondDao(CategorySecondDao categorySecondDao) {
		this.categorySecondDao = categorySecondDao;
	}

	public PageBean<CategorySecond> findByPage(Integer page) {
		PageBean<CategorySecond> pageBean = new PageBean<CategorySecond>();
		pageBean.setPage(page);
		pageBean.setLimit(Constant.CSLIMIT);
		//pageBean.s
		Integer totalCount = categorySecondDao.findCount();
		pageBean.setTotalCount(totalCount);
		Integer totalPage = 0;
		if(totalCount % Constant.CSLIMIT == 0){
			totalPage = totalCount/Constant.CSLIMIT;
		}else{
			totalPage = totalCount/Constant.CSLIMIT + 1;
		}
		pageBean.setTotalPage(totalPage);
		
		Integer begin = (page - 1)*Constant.CSLIMIT;
		System.out.println("=================="+begin);
		List<CategorySecond> categorySeconds = categorySecondDao.findByPage(begin, Constant.CSLIMIT);
		pageBean.setList(categorySeconds);
		
		return pageBean;
	}

	public void save(CategorySecond categorySecond) {
		categorySecondDao.save(categorySecond);
	}

	public void delete(CategorySecond categorySecond) {
		categorySecondDao.delete(categorySecond);
	}

	public CategorySecond findByCsid(Integer csid) {
		CategorySecond categorySecond = categorySecondDao.findByCsid(csid);
		return categorySecond;
	}

	public void update(CategorySecond categorySecond) {
		categorySecondDao.update(categorySecond);
	}

	public List<CategorySecond> findAll() {
		
		return categorySecondDao.findAll();
	}

}
